package
{
	import generated.webservices.ArrayOfTag;
	import generated.webservices.ArrayOfTagTreeInfo;
	import generated.webservices.Tag;
	import generated.webservices.TagTreeInfo;

	public class CheckableTagTreeInfo extends TagTreeInfo
	{	
		[Bindable]
		public var checked: Boolean;
	
		public static function FindByID(items: ArrayOfTag, id: Number): Number
		{
			var res: Number = 0;
			for each (var i: Tag in items){
				if (i.ID == id)
					return res;
				++res;
			}
			return -1;
		}
		
		
		public function CheckableTagTreeInfo(treeToClone: TagTreeInfo, checkedItems: ArrayOfTag)
		{
			super();
				
			checked = (FindByID(checkedItems, treeToClone.ID) >= 0);
			
			this.ID = treeToClone.ID;
			this.Name = treeToClone.Name;
			this.Children = new ArrayOfTagTreeInfo();
			
			var ind: Number = 0;
			for each (var t: TagTreeInfo in treeToClone.Children)
			{
				Children.addItem(new CheckableTagTreeInfo(t, checkedItems));
				++ind;
			}
		}
	}
}